package org.yaac.server.egql;

import static com.google.common.base.Strings.isNullOrEmpty;

import java.io.Serializable;



/**
 * entity and property, the basic meta url for a field
 * 
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
@Deprecated
public class EntityProperty implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private final String entityName;

	private final String propertyName;
	
	public EntityProperty(String entityName, String propertyName) {
		super();
		this.entityName = entityName;
		this.propertyName = propertyName;
	}

	public String getEntityName() {
		return entityName;
	}
	
	public String getPropertyName() {
		return propertyName;
	}
	
	/**
	 * @return
	 */
	public String asString() {
		return isNullOrEmpty(entityName) ? propertyName : entityName + "." + propertyName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((entityName == null) ? 0 : entityName.hashCode());
		result = prime * result + ((propertyName == null) ? 0 : propertyName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EntityProperty other = (EntityProperty) obj;
		if (entityName == null) {
			if (other.entityName != null)
				return false;
		} else if (!entityName.equals(other.entityName))
			return false;
		if (propertyName == null) {
			if (other.propertyName != null)
				return false;
		} else if (!propertyName.equals(other.propertyName))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "EntityProperty [entityName=" + entityName + ", propertyName=" + propertyName + "]";
	}
}
